﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Script.Services;
namespace JTicket.UI.Service
{
    /// <summary>
    /// Summary description for JT_OperSvc
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    [System.Web.Script.Services.ScriptService]
    [GenerateScriptType(typeof(JTicket.Model.OperInfo))]
    [GenerateScriptType(typeof(JTicket.Model.D_OperInfo))]
    [GenerateScriptType(typeof(JTicket.Model.C_CodeNote))]
    [GenerateScriptType(typeof(JTicket.Model.C_TheaterInfo))]
    public class JT_OperSvc : System.Web.Services.WebService
    {
        [WebMethod]
        public JTicket.Model.D_OperInfo GetModel(string OperCode)
        {
            BLL.D_OperInfo bllOper = new BLL.D_OperInfo();

            return bllOper.GetModel(OperCode);

        }
        [WebMethod]
        public void Update(JTicket.Model.OperInfo model)
        {
            try
            {
                JTicket.Model.D_OperInfo Oper = new Model.D_OperInfo();
                Oper.barcode = model.barcode;
                Oper.ThCode = model.ThCode;
                Oper.ThName = model.ThName;
                Oper.CompanyCode = model.CompanyCode;
                Oper.CurCheckNum = 0;
                Oper.CurLevel = char.Parse(model.CurLevel);
                Oper.CurStatus = char.Parse(model.CurStatus);
                Oper.OperName = model.OperName;
                //Oper.Password = Common.DESEncrypt.Encrypt("888888");
                Oper.OperCode = model.OperCode;
                Oper.SaleType = model.SaleType;
                Oper.ZheKou = 10.0M;
                BLL.D_OperInfo.Update(Oper);
                string[] Str = model.Roles.TrimEnd('|').Split('|');
                if (Str.Length > 0)
                {
                    BLL.M_OperRight.Update2(model.OperCode);
                    for (int i = 0; i <= Str.Length - 1; i++)
                    {
                        BLL.M_OperRight.Update(model.OperCode, Str[i], 1);
                    }
                }
            }
            catch { }
        }
        /// <summary>
        /// 增加一条数据
        /// </summary>
        [WebMethod]
        public string Add(JTicket.Model.OperInfo model)
        {
            if (!BLL.D_OperInfo.Exists(model.OperCode))
            {

                if (BLL.D_OperInfo.ExistsBarCode(model.barcode))
                    return "此员工条码已存在！";
                else
                {
                    JTicket.Model.D_OperInfo Oper = new Model.D_OperInfo();
                    Oper.ThCode = model.ThCode;
                    Oper.ThName = model.ThName;
                    Oper.barcode = model.barcode;
                    Oper.CompanyCode = model.CompanyCode;
                    Oper.CurCheckNum = 0;
                    Oper.CurLevel = char.Parse(model.CurLevel);
                    Oper.CurStatus = char.Parse(model.CurStatus);
                    Oper.OperCode = model.OperCode;
                    Oper.OperName = model.OperName;
                    Oper.Password = Common.DESEncrypt.Encrypt("888888");
                    Oper.SaleType = model.SaleType;
                    Oper.ZheKou = 10.0M;
                    BLL.D_OperInfo.Add(Oper);
                    string[] Str = model.Roles.TrimEnd('|').Split('|');
                    if (Str.Length > 0)
                    {
                        for (int i = 0; i <= Str.Length - 1; i++)
                        {
                            BLL.M_OperRight.Update(model.OperCode, Str[i], 1);
                        }
                    }
                    return "操作成功！";

                }
            }
            else
                return "此用户账号已存！";
        }
        [WebMethod]
        public string Delete(string OperCode)
        {
            BLL.D_OperInfo bllOper = new BLL.D_OperInfo();

            if (!bllOper.Oper().OperCode.Equals(OperCode))
            {
                string[] operCode = OperCode.TrimEnd('|').Split('|');
                foreach (var code in operCode)
                {
                    BLL.D_OperInfo.Delete(code);
                }
                return "删除成功！";
            }
            else
                return "此用户已登录中,暂不能删除！";
        }
        [WebMethod]
        public string isRePwd(string OperCode)
        {

            if (BLL.D_OperInfo.Exists(OperCode))
            {
                BLL.D_OperInfo.isRePwd(OperCode);
                return "此账号密码已重置成：888888。";
            }
            else
                return "不存在此用户账号！";
        }

        /// <summary>
        /// 获得剧院列表数据列表
        /// </summary>
        [WebMethod]
        public List<Model.C_TheaterInfo> Th_GetList()
        {
            BLL.C_TheaterInfo bllTheaterInfo = new BLL.C_TheaterInfo();
            int pages = 0;
            return bllTheaterInfo.GetListByCurLevel(0, 200, ref pages, "");
        }

        /// <summary>
        /// 用户等级
        /// </summary>
        /// <returns></returns>
        [WebMethod]
        public List<Model.C_CodeNote> Oper_Level()
        {
            BLL.C_CodeNote bllCodeNote = new BLL.C_CodeNote();
            return bllCodeNote.GetListAllByGroupCod();
        }

        [WebMethod]
        public List<Model.C_CodeNote> GetListAllRoles(string level)
        {
            return BLL.C_CodeNote.GetListAllRoles(level);
        }


        [WebMethod]
        public List<Model.M_OperRight> GetRoleList(string OperCode)
        {
            return BLL.M_OperRight.GetRoleListM(OperCode);
        }
    }
}
